package com.itstudy.mapper;

import com.github.pagehelper.Page;
import com.itstudy.pojo.Article;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.DeleteMapping;

@Mapper
public interface ArticleMapper {

    @Insert("insert into article (title, content, cover_img,state, category_id, create_user, create_time, update_time) " +
            "VALUES (#{title},#{content},#{coverImg},#{state},#{categoryId},#{createUser},now(),now())")
    void insert(Article article);

    Page<Article> pageQuery(Integer categoryId, String state, Integer id);

    @Select("select * from article where id=#{id}")
    Article getDetail(Integer id);

    @Update("update article set title=#{title},content=#{content},cover_img=#{coverImg},category_id=#{categoryId},create_user=#{createUser},update_time=now() " +
            "where id=#{id}")
    void updateArticle(Article article);

    @Delete("delete from article where id=#{id}")
    int deleteById(Integer id);
}
